package com.hgk.wanwan.main.fragment.whatfragment.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

/**
 * Created by lenovo on 2016/10/14.
 */
public class PagerCenterAdapter extends PagerAdapter {
    private Context mContext;
    private  ImageView[] lists;
    private LayoutInflater inflater;

    public PagerCenterAdapter(Context context, ImageView[] mList) {
        this.mContext = context;
        this.lists = mList;
        inflater = LayoutInflater.from(mContext);
    }


    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public void destroyItem(View container, int position, Object object) {
        ((ViewPager)container).removeView(lists[position % lists.length]);

    }

    /**
     * 载入图片进去，用当前的position 除以 图片数组长度取余数是关键
     */
    @Override
    public Object instantiateItem(View container, int position) {
        ((ViewPager)container).addView(lists[position % lists.length], 0);
        return lists[position % lists.length];
    }

}
